<extend name="Public:base" />
<block name="content">
	<form id="validation-form" method="post">
    <style type="text/css">
        li{
            list-style: none;;
        }
		table{
			text-align: center;
		}
		.mytableer tbody > tr > td{
			border: none;
		}
		.popuping{
			z-index: 1050;
			width: auto;
			padding: 10px;
			margin-right: auto;
			margin-left: auto;

		}
		.bootbox.fade .popuping{
			-webkit-transform: translate(0,-25%);
			-ms-transform: translate(0,-25%);
			transform: translate(0,-25%);
			-webkit-transition: -webkit-transform .3s ease-out;
			-moz-transition: -moz-transform .3s ease-out;
			-o-transition: -o-transform .3s ease-out;
			transition: transform .3s ease-out;
		}
		.bootbox.in .popuping{
			-webkit-transform: translate(0,0);
			-ms-transform: translate(0,0);
			transform: translate(0,0);
		}
		.bootbox.in .popuping-content{
			position: relative;
			background-color: #fff;
			border: 1px solid #999;
			border: 1px solid rgba(0,0,0,0.2);
			border-radius: 6px;
			outline: 0;
			-webkit-box-shadow: 0 3px 9px rgba(0,0,0,0.5);
			box-shadow: 0 3px 9px rgba(0,0,0,0.5);
			background-clip: padding-box;
			padding: 20px;
			margin: 100px auto 0;
		}
		.ui-jqdialog-content .FormData > td{
			width: 20%;
		}
		.ui-jqdialog-content .FormData #sdate{
			width: 350px!important;
		}
    </style>
   <div class="table-responsive">
    <table class="table table-striped table-bordered table-hover search-form">
			<thead>
		    <th>
		    订单号：<input name="order_id" type="text" placeholder="" value="{:I('order_id')}" style="width:95px;" />

			操作人：<input name="name" type="text" placeholder="" value="{:I('name')}" style="width:95px;" />

			类型：<select name="type" style="width:95px;">
				<php>if(I('type')==0){</php>
				<option value="0" selected="selected">全部</option>
				<option value="1">全退</option>
				<option value="2">退维保金</option>
				<php>}else if(I('type')==1){</php>
				<option value="0">全部</option>
				<option value="1" selected="selected">全退</option>
				<option value="2">退维保金</option>
				<php>}else if(I('type')==2){</php>
				<option value="0">全部</option>
				<option value="1">全退</option>
				<option value="2" selected="selected">退维保金</option>
				<php>}</php>
				 </select>
			操作时间：<input id="startDate" style="width:135px;" name="start_time" value="{:I('start_time')}" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-M-d 00:00:00'})"/> - <input id="endDate" name="end_time" style="width:135px;" value="{:I('end_time')}" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-M-d 00:00:00'})"/>

			状态：<select name="status" style="width:95px;">
				<php>if(I('status')==0){</php>
				<option value="0" selected="selected">全部</option>
				<option value="1">未转账</option>
				<option value="2">已转账</option>
				<php>}else if(I('status')==1){</php>
				<option value="0">全部</option>
				<option value="1" selected="selected">未转账</option>
				<option value="2">已转账</option>
				<php>}else if(I('status')==2){</php>
				<option value="0">全部</option>
				<option value="1">未转账</option>
				<option value="2" selected="selected">已转账</option>
				<php>}</php>
			</select>
			<a class="btn btn-primary btn-sm radius5" href="javascript:;" id="search" url="{:U('Order/handleRefund')}">查询</a>
			</th>
			</thead>
		</table>
   </div>
</form>
<div class="table-responsive">
	<table class="table table-striped table-bordered table-hover" id="mytable">
		<thead>
			<tr>
				<th>订单编号</th>
				<th>退款金额</th>
				<th>业主获款</th>
				<th>师傅获款</th>
				<th>类型</th>
				<th>状态</th>
				<th>操作时间</th>
				<th>操作人</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
				<volist name="handle" id="vo">
				<tr>
					<td>{$vo.repair_order_num_alias}<br><a href="{:U('order/normal')}/order_id/{$vo.repair_order_id}">[查看订单]</a></td>
					<td>¥{$vo.total}</td>
					<td>¥{$vo.user_refund}<php>if($vo['user_code']){</php>
					<br>流水号：{$vo['user_code']}
					<php>}</php>
					</td>
					<td>¥{$vo.master_refund}
						<php>if($vo['master_code']){</php>
						<br>流水号：{$vo['master_code']}
						<php>}</php>
					</td>
					<td>{$vo.type}</td>
					<td>{$vo.status}</td>
					<td>{$vo.add_time}</td>
					<td>{$vo.name}</td>
					<php>if($vo['status']=='已转账'){</php>
					<td><button class="btn btn-xs btn-info radius5">已转账</button></td>
					<php>}else{</php>
					<td><button id="add" name="{$vo.repair_order_id}" class="btn btn-xs btn-info radius5">转账</button></td>
					<php>}</php>
				</tr>
				</volist>
				<tr>
					<td colspan="20" class="page">{$page}</td>
				</tr>
		</tbody>
	</table>
</div>
	<div class="bootbox modal fade">
		<div class="popuping">
			<div class="popuping-content" style="width: 80%;">
				<div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table">
					<h3>转账</h3>
					<div>
						<form name="FormPost" id="FrmGrid_grid-table" class="FormGrid" onsubmit="return false;" style="width:auto;overflow:auto;position:relative;height:auto;">
							<table  id="TblGrid_grid-table-user" class="EditTable" cellspacing="0" cellpadding="0" border="0">
								<tbody>
								<h4 class="user">业主转账信息</h4>
								<tr id="FormError" style="display:none">
									<td class="ui-state-error" colspan="2"></td>
								</tr>
								<tr style="display:none" class="tinfo">
									<td class="topinfo" colspan="2"></td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">退款方式：</td>
									<td class="DataTD">&nbsp;
										<span class="channel"></span>
									</td>
									<td class="CaptionTD">开户行：</td>
									<td class="DataTD">&nbsp;
										<span class="bankName"></span>
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">户名：</td>
									<td class="DataTD">&nbsp;
										<span class="account_name"></span>
									</td>
									<td class="CaptionTD">卡号：</td>
									<td class="DataTD">&nbsp;
										<span class="account_num"></span>
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">联系方式：</td>
									<td class="DataTD">&nbsp;
										<span class="user_phone"></span>
									</td>
									<td class="CaptionTD">操作人：</td>
									<td class="DataTD">&nbsp;
										<span class="admin_name"></span>
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">转账流水号：</td>
									<td class="DataTD">&nbsp;
										<input style="width: 200px" type="number" id="sdate" name="flow_num" role="textbox" class="FormElement ui-widget-content ui-corner-all">
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">备注：</td>
									<td class="DataTD">&nbsp;
										<input style="width: 200px" type="text" id="sdate" name="user_record" role="textbox" class="FormElement ui-widget-content ui-corner-all">
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">客服判定金额：</td>
									<td class="DataTD" style="width:20px;">&nbsp;
										¥<span class="user_refund"></span>
									</td>
								</tr>
								</tbody>
							</table>
							<table  id="TblGrid_grid-table-master" class="EditTable" cellspacing="0" cellpadding="0" border="0">
								<tbody>
								<h4 class="master">师傅转账信息</h4>
								<tr id="FormError" style="display:none">
									<td class="ui-state-error" colspan="2"></td>
								</tr>
								<tr style="display:none" class="tinfo">
									<td class="topinfo" colspan="2"></td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">退款方式：</td>
									<td class="DataTD">&nbsp;
										<span>余额退款</span>
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">户名：</td>
									<td class="DataTD">&nbsp;
										<span class="worker_name"></span>
									</td>
									<td class="CaptionTD">账号：</td>
									<td class="DataTD">&nbsp;
										<span class="worker_phone"></span>
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">联系方式：</td>
									<td class="DataTD">&nbsp;
										<span class="worker_phone"></span>
									</td>
									<td class="CaptionTD">操作人：</td>
									<td class="DataTD">&nbsp;
										<span class="admin_name"></span>
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">转账流水号：</td>
									<td class="DataTD" style="width:200px;">&nbsp;
										<span>师傅退款将自动转账到余额，确认转账后自动生成流水号</span>
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">备注：</td>
									<td class="DataTD" style="width:20px;">&nbsp;
										<input style="width: 200px" type="text" id="sdate" name="master_record" role="textbox" class="FormElement ui-widget-content ui-corner-all">
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">客服判定金额：</td>
									<td class="DataTD" style="width:20px;">&nbsp;
										¥<span class="master_refund"></span>
									</td>
								</tr>
								<input type="hidden" name="order_id" value=""/>
								</tbody>
							</table>
						</form>
						<div style="text-align: center;">
							<button class="btn btn-xs btn-info radius5 marginT10" id="save">确认转账</button>
							<button class="btn btn-xs btn-info radius5 marginT10" style="margin-left: 100px;" id="cancel">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="javascript">
<script>
$(function(){

	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });

	$("[id=add]").on("click",function(){
		var order_id = $(this).attr("name");

		$.ajax({
			url:"{:U('Order/accountInfo')}",
			type:"post",
			data:{
				order_id : order_id
			},
			success:function(data){
//				console.log(data);
//				return false;
				if(data) {
					if(data[0].check==0){
						if (data[0].master_refund == 0.000) {
							$("#TblGrid_grid-table-master").hide();
							$(".master").hide();
						}
						if (data[0].user_refund == 0.000) {
							$("#TblGrid_grid-table-user").hide();
							$(".user").hide();
						}
						$(".channel").html(data[0].channel);
						$(".bankName").html(data[0].bank_name);
						$(".account_name").html(data[0].account_name);
						$(".account_num").html(data[0].account_num);
						$(".user_refund").html(data[0].user_refund);
						$(".user_phone").html(data[0].user_phone);

						$(".admin_name").html(data[0].admin_name);

						$(".worker_name").html(data[0].worker_name);
						$(".worker_phone").html(data[0].worker_phone);
						$(".master_refund").html(data[0].master_refund);
						$("input[name=order_id]").val(order_id);

						$("body").append("<div class=\"modal-backdrop fade in\"></div>");
						$(".bootbox.modal.fade").addClass("in").show(1100);

						if(!data[0].account_name && !data[0].account_num){
							$.jbox.info('等待业主提交退款信息！','提示');
							return false;
						}
					}else if(data[0].check==1){
						console.log(data)
						$("#TblGrid_grid-table-user").hide();
						$(".user").hide();

						$(".admin_name").html(data[0].admin_name);

						$(".worker_name").html(data[0].worker_name);
						$(".worker_phone").html(data[0].worker_phone);
						$(".master_refund").html(data[0].master_refund);
						$("input[name=order_id]").val(order_id);

						$("body").append("<div class=\"modal-backdrop fade in\"></div>");
						$(".bootbox.modal.fade").addClass("in").show(1100);
					} else if(data[0].check==2) {
						if (!data[0].account_name && !data[0].account_num) {
							$.jbox.info('等待业主提交退款信息！', '提示');
							return false;
						}

						if (data[0].master_refund == 0.00) {
							$("#TblGrid_grid-table-master").hide();
							$(".master").hide();
						}
						$(".channel").html(data[0].channel);
						$(".bankName").html(data[0].bank_name);
						$(".account_name").html(data[0].account_name);
						$(".account_num").html(data[0].account_num);
						$(".user_refund").html(data[0].user_refund);
						$(".user_phone").html(data[0].user_phone);

						$(".admin_name").html(data[0].admin_name);

						$(".worker_name").html(data[0].worker_name);
						$(".worker_phone").html(data[0].worker_phone);
						$(".master_refund").html(data[0].master_refund);
						$("input[name=order_id]").val(order_id);

						$("body").append("<div class=\"modal-backdrop fade in\"></div>");
						$(".bootbox.modal.fade").addClass("in").show(1100);
					}

				}

			}

		});

	});

	$('#cancel').click(function(){
		$(".bootbox.modal.fade").addClass("in").hide(400);
		setTimeout(function(){
			$(".modal-backdrop.fade.in").remove()
		},200);
	});

	$("#save").click(function(){
		var flow_num = Number($("input[name=flow_num]").val());
		var user_remark = $("input[name=user_record]").val();
		var master_remark = $("input[name=master_record]").val();
		var order_id = $("input[name=order_id]").val();

		if($(".user_refund").html()!=0.00) {
			if (flow_num == '') {
				$.jbox.info('请输入流水号！', '提示');
				return false;
			}
		}

		$.ajax({
			url:"{:U('Order/refundSuc')}",
			type:"post",
			data:{
				flow_num : flow_num,
				user_remark: user_remark,
				master_remark:master_remark,
				order_id:order_id
			},
			success:function(data){
				if(data=='1'){
					$.jbox.tip("处理成功！", 'loading');
					window.setTimeout(function () {window.location.reload() }, 500);
				}else if(data=='3'){
					$.jbox.info("操作失败！",'提示');
				}
			}
		})

	});

});
</script>
</block>